<div id="content">
#{form @ManageUser.save()}
 #{if flash.error}
    <p class="error">&{'manageusertype.error.emptydescription'}</p>
 #{/if}
 #{if flash.success}
    <p class="success">${flash.success}</p>
 #{/if}
<table class="tableau">
	<tr>
		<td>
			<label for="userID">&{'table.requesttype.id'}</label>
		
		</td>
		<td>
			<input type="text" id="userID" disabled=true value="${user?.getId()}" />
		</td>
	</tr>
	<tr>
		<td>
			<label for="fullname">&{'table.usermanager.name'}</label>
		</td>
		<td>
			<input type="text" name="fullName" id="fullName" size="30" value="${user?.getFullName()}" />
		</td>
	</tr>
	<tr>
		<td>
			<label for="email">&{'table.usermanager.email'}</label>
		</td>
		<td>
			<input type="text" name="email" id="email" size="30" value="${user?.getEmail()}" />
		</td>
	</tr>
	<tr>
		<td>
			<label for="active">&{'table.usermanager.isactif'}</label>
		</td>
		<td>
			<input type="checkbox" value="active" name="active" id="active" #{if user?.getActive()}checked#{/if} />
		</td>
	</tr>
	<tr>
		<td>
			<label for="admin">&{'table.usermanager.isadmin'}</label>
		</td>
		<td>
			 
			<input type="checkbox" value="admin" name="admin" id="admin" #{if user?.getAdmin()}checked#{/if} />
		</td>
	</tr>
	<tr>
		<td>
			<label for="userType">&{'table.usermanager.type'} </label>
		</td>
		<td>
			<select id="userType" name="userType">
				#{list items:userTypes, as:'type'}
					<option value="${type.getId()}" 
						#{if type.getId() == user?.getTypeId() }
    						selected="true"
						#{/if}>${type.getDescription()}
						
					</option>
				#{/list}
			</select>
		</td>
	</tr>
	<tr>
	<td colspan="2">
		<a id="add" href="#">&{'managerequesttype.addedit'}</a>
		<a id="delete" href="#">&{'managerequesttype.delete'}</a>
		<a id="cancel" href="#">&{'managerequesttype.cancel'}</a>
	</td>
	</tr>
</table>
#{/form}
</div>

<script>
	$(function() {
		
		$("#add").button().click(function() {
			// Define Create Action
			
			var createAction = #{jsAction @ManageUser.save(':userID',':fullName',':email'
										,':active',':admin',':userType') /}
			// Call Create Action
			$.post(createAction({id: $('#userID').val(), fullName: $('#fullName').val(), email: $('#email').val(),
									active: $('#active:checked').val(),admin: $('#admin:checked').val(),userType: $('#userType').val()}), function(data) {
				// Prepend Results to the List
				$('#content').replaceWith(data);
			});
		});
		
		$("#delete").button().click(function() {
			// Define delete Action
			var createAction = #{jsAction @ManageUser.deleteUser(':userId') /}
			// Call Create Action
			$.post(createAction({userId:$('#userID').val()}), function(data) {
				// Prepend Results to the List
				$('#content').replaceWith(data);
			});
		});

		$("#cancel").button().click(function() {
			// Define Cancel Action
			var createAction = #{jsAction @index() /}
			// Call Cancel Action
			$.post(createAction(), function(data) {
				// Prepend Results to the List
				
				$('#content').replaceWith(data);
			});
		});
	});
</script>